#!/usr/bin/env bash
#
# base from https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04
#

package_name=modbus-test
package_main_file=main.go

platforms=("windows/amd64" "linux/amd64" "linux/arm" "linux/arm64")

for platform in "${platforms[@]}"
do
	platform_split=(${platform//\// })
	GOOS=${platform_split[0]}
	GOARCH=${platform_split[1]}
	output_name=$package_name'-'$GOOS'-'$GOARCH
	if [ $GOOS = "windows" ]; then
		output_name+='.exe'
	fi

  echo "building $output_name ..."
	env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package_main_file
	if [ $? -ne 0 ]; then
   		echo 'An error has occurred! Aborting the script execution...'
		exit 1
	fi
done